package com.ruibo.tax.service.impl;

import com.ruibo.tax.model.base.PackageHead;
import com.ruibo.tax.model.log.TaxLog;
import com.ruibo.tax.repository.TaxLogRepository;
import com.ruibo.tax.service.TaxLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.time.LocalDateTime;


@Service
public class TaxLogServiceImpl implements TaxLogService {

    @Autowired
    private TaxLogRepository taxLogRepository;

    @Override
    @Transactional
    public TaxLog handlerData(PackageHead heads) {
        TaxLog taxLog = new TaxLog();
        taxLog.setPkg_num(heads.getSJBBH());
        taxLog.setPkg_type(heads.getSJBLX());
        taxLog.setUnit_code(heads.getDWDM());
        taxLog.setUnit_name(heads.getDWMC());
        taxLog.setRecord_num(heads.getJLS());
        // 表名
        taxLog.setType(pkgTypeToType(heads.getSJBLX()));
        taxLog.setCreateAt(LocalDateTime.now());
        taxLog.setUpdateAt(LocalDateTime.now());
        TaxLog save = taxLogRepository.save(taxLog);
        return save;
    }

    private String pkgTypeToType(String pkgType) {
        String type = "";
        switch (pkgType) {
            case "FHTQXX":
                type = "swhb_swfhtq";
                break;
            case "SWSSQY":
                type = "swhb_qysscjs";
                break;
            case "SWJCSY":
                type = "swhb_qysysscj";
                break;
            case "SSGTFW":
                type = "swhb_qytifwxxcj";
                break;
            case "SSZSXX":
                type = "swhb_qyzsxxcj";
                break;
            case "CPWXSJC":
                type = "swhb_swcpwxsjcxx";
                break;
            case "DQWRNSSB":
                type = "swhb_dqwrwnssbjsxx";
                break;
            case "SWRNSSB":
                type = "swhb_swrwnssbjsxx";
                break;
            case "GTFWNSSB":
                type = "swhb_gtfwnssbjsxx";
                break;
            case "ZSNSSB":
                type = "swhb_zswrsbjsxx";
                break;
            case "JMMXNSSB":
                type = "swhb_jmsmxjsxx";
                break;
            case "SWNSSBB":
                type = "swhb_nssbxxb";
                break;
            case "SWRKXX":
                type = "swhb_nsrrksj";
                break;
            case "SSDQSWR":
                type = "swhb_dqswrrsscj";
                break;
            case "SWNSSBA":
                type = "swhb_nssbxx";
                break;
            default:
                type = "";
        }
        return type;
    }

}
